<?php
/**
 * Created by PhpStorm.
 * User: 12133
 * Date: 2022/12/7
 * Time: 21:12
 */

namespace app\controller\sys;
use app\model\sys\SysChannel AS model;
class Channel extends Base
{
    public function list(){
        $where = [];
        $post = input('post.');
        !empty($this->start_time) && $where[] = ['expire_time','>=',$this->start_time];
        !empty($this->end_time) && $where[] = ['expire_time','<=',$this->end_time];
        $list = model::where($where)
            ->order('id DESC')
            ->paginate([
                'page' => $this->page,
                'list_rows' => $this->size
            ]);
        return $this->msg($list);
    }

    public function info(){
        $id = input('uuid');
        $user = model::where('id',$id)->find();
        return $this->msg($user);
    }

    public function save(){
        $post = input('post.');
        if (empty($post['id'])) {
            model::create($post);
        }else{
            $find = model::where('id',$post['id'])->find();
            if (empty($find->id))
                return $this->fail('数据不存在');
            $find->save($post);
        }
        return $this->msg();
    }

    public function del(){
        $user_id = input('id');
        $find = model::where('id',$user_id)->find();
        if (empty($find->id))
            return $this->fail('数据不存在');
        $find->delete();
        return $this->msg();
    }
}